package grupo1.fotomultas.Fotomultas;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class HomeVehiculos {
	
	private static HomeVehiculos instance;
	private Map<String, Vehiculo> flotaVehicular = new HashMap<String, Vehiculo>();
	
	public void agregarVehiculo(Vehiculo unVehiculo){ 
		
		if(this.flotaVehicular.containsKey(unVehiculo.getPatente())){
			throw new VehiculoExistenteException("El Vehiculo con la patente " + unVehiculo.getPatente()+" ya existe");
		}
			
		this.flotaVehicular.put(unVehiculo.getPatente(), unVehiculo);
	}

	public static HomeVehiculos Instance() {
		if(instance==null)
			instance = new HomeVehiculos();
		return instance; 
	}

	public boolean existeVehiculo(String patente) {
		return flotaVehicular.containsKey(patente);
	}
	
	public Vehiculo obtenerUnVehiculo(String patente) {
		Vehiculo unVehiculo = flotaVehicular.get(patente);
		
		if(unVehiculo == null){
			throw new VehiculoInexistenteException("El Vehiculo con la patente " + patente +" no existe");
		}
		return unVehiculo;
	}

	public void reset() {
		this.flotaVehicular = new HashMap<String, Vehiculo>();
		
	}
	
	public Set<Vehiculo> obtenerVehiculos(){
		return new HashSet <Vehiculo>(flotaVehicular.values());
	}


}
